package com.css.fxfzaqbz.modules.estimate.controller;

import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.estimate.vo.EstimateVo;
import com.css.fxfzaqbz.modules.estimate.service.FaultService;
import com.css.fxfzaqbz.modules.supergraph.exception.CustomException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 断层分布评估结果
 */
@Slf4j
@RestController
@RequestMapping("/estimate/fault")
public class FaultController {

    @Autowired
    private FaultService faultService;
    //仅保存结果
    @PostMapping("/save")
    public RestResponse saveFault(@RequestBody EstimateVo vo){
        RestResponse restResponse=null;
        try {
            faultService.saveFault(vo.getIaId(),vo.getDataVersion());
            restResponse = RestResponse.succeed();
        }catch (CustomException e){
            log.error("保存结果失败!",e.getMessage());
            restResponse = RestResponse.fail(e.getMessage());
        }catch (Exception e) {
            log.error("保存结果失败!",e);
            restResponse = RestResponse.fail("保存结果失败");
        }
        return restResponse;
    }

    //根据评估结果id下载shp
    @PostMapping("/downLoadShp/{resultAnalysis}")
    public RestResponse<String> downLoadShp(@PathVariable String resultAnalysis, HttpServletResponse response) {
        RestResponse<String> restResponse = null;
        try {
            faultService.downLoadShp(resultAnalysis, response);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("修改失败", e);
            restResponse = RestResponse.fail("修改失败");
        }
        return restResponse;
    }
}
